/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author WinKiQue58
 */
@Entity
@Table(name = "MESSAGE")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Message.findAll", query = "SELECT m FROM Message m"),
    @NamedQuery(name = "Message.findByIdMessage", query = "SELECT m FROM Message m WHERE m.messagePK.idMessage = :idMessage"),
    @NamedQuery(name = "Message.findByIdPersonalInfo", query = "SELECT m FROM Message m WHERE m.messagePK.idPersonalInfo = :idPersonalInfo"),
    @NamedQuery(name = "Message.findByIdBranchenterprise", query = "SELECT m FROM Message m WHERE m.messagePK.idBranchenterprise = :idBranchenterprise"),
    @NamedQuery(name = "Message.findByIdEnterprise", query = "SELECT m FROM Message m WHERE m.messagePK.idEnterprise = :idEnterprise"),
    @NamedQuery(name = "Message.findByS3r4To", query = "SELECT m FROM Message m WHERE m.s3r4To = :s3r4To"),
    @NamedQuery(name = "Message.findBySubject", query = "SELECT m FROM Message m WHERE m.subject = :subject"),
    @NamedQuery(name = "Message.findByMessage", query = "SELECT m FROM Message m WHERE m.message = :message"),
    @NamedQuery(name = "Message.findByS3r4From", query = "SELECT m FROM Message m WHERE m.s3r4From = :s3r4From")})
public class Message implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected MessagePK messagePK;
    @Size(max = 180)
    @Column(name = "S3R4_TO")
    private String s3r4To;
    @Size(max = 180)
    @Column(name = "SUBJECT")
    private String subject;
    @Size(max = 800)
    @Column(name = "MESSAGE")
    private String message;
    @Size(max = 180)
    @Column(name = "S3R4_FROM")
    private String s3r4From;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "message", fetch = FetchType.LAZY)
    private List<MessageStatus> messageStatusList;
    @JoinColumns({
        @JoinColumn(name = "ID_PERSONAL_INFO", referencedColumnName = "ID_PERSONAL_INFO", insertable = false, updatable = false),
        @JoinColumn(name = "ID_BRANCHENTERPRISE", referencedColumnName = "ID_BRANCHENTERPRISE", insertable = false, updatable = false),
        @JoinColumn(name = "ID_ENTERPRISE", referencedColumnName = "ID_ENTERPRISE", insertable = false, updatable = false)})
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private PersonalInfo personalInfo;

    public Message() {
    }

    public Message(MessagePK messagePK, String TO,String message,String Who) {
        this.messagePK = messagePK;
        this.s3r4To=TO;
        this.message=message;
        this.s3r4From=Who;
    }

    public Message(BigInteger idMessage, BigInteger idPersonalInfo, BigInteger idBranchenterprise, BigInteger idEnterprise) {
        this.messagePK = new MessagePK(idMessage, idPersonalInfo, idBranchenterprise, idEnterprise);
    }

    public MessagePK getMessagePK() {
        return messagePK;
    }

    public void setMessagePK(MessagePK messagePK) {
        this.messagePK = messagePK;
    }

    public String getS3r4To() {
        return s3r4To;
    }

    public void setS3r4To(String s3r4To) {
        this.s3r4To = s3r4To;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getS3r4From() {
        return s3r4From;
    }

    public void setS3r4From(String s3r4From) {
        this.s3r4From = s3r4From;
    }

    @XmlTransient
    public List<MessageStatus> getMessageStatusList() {
        return messageStatusList;
    }

    public void setMessageStatusList(List<MessageStatus> messageStatusList) {
        this.messageStatusList = messageStatusList;
    }

    public PersonalInfo getPersonalInfo() {
        return personalInfo;
    }

    public void setPersonalInfo(PersonalInfo personalInfo) {
        this.personalInfo = personalInfo;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (messagePK != null ? messagePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Message)) {
            return false;
        }
        Message other = (Message) object;
        if ((this.messagePK == null && other.messagePK != null) || (this.messagePK != null && !this.messagePK.equals(other.messagePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Message[ messagePK=" + messagePK + " ]";
    }
    
}
